# set compiler
CC = g++

# set compilation flags
#CC_FLAGS := -O0 -g
#CC_FLAGS := -O2 -DNDEBUG -pthread
CC_FLAGS := -O2 -DNDEBUG

# specify boost header file directory
#BOOST_DIR := /usr/local/boost_1_39_0/include/boost-1_39/
BOOST_DIR := /home/Eric/software/boost_1_47_0/

# setup for blas/lapack
#BLAS_LAPACK_INC := -DHAVE_MKL -I/srv/usr/local/opt/intel/mkl/10.2.1.017/include/
#BLAS_LAPACK_LIB := -L/srv/usr/local/opt/intel/mkl/10.2.1.017/lib/em64t -lguide -lmkl_core -lmkl_intel_thread -lmkl_intel_lp64
BLAS_LAPACK_INC :=
BLAS_LAPACK_LIB := -L/home/Eric/software/lapack-3.3.1/ -llapack -lblas -L/lib/gcc/i686-pc-cygwin/4.5.3/ -lgfortran

# specify include directories
GLOBAL_INC := -I./ -I$(BOOST_DIR) $(BLAS_LAPACK_INC)

# create list of object files
objects := $(subst src/,obj/,$(subst .cpp,.o,$(wildcard src/*.cpp)))

# create list of dependency files
dependencies := $(subst src/,dep/,$(subst .cpp,.d,$(wildcard src/*.cpp)))

# when make is run with no arguments, create the executable
.PHONY : default
default : bin/eds.exe

# for each object file foo.o, create a dependency file foo.d in the dep/ directory
$(dependencies) : dep/%.d : src/%.cpp
	@echo "updating dependencies for $<";
	@$(CC) $(CC_FLAGS) $(GLOBAL_INC) -MM $< | sed -e "s/$*\.o/obj\/$*.o dep\/$*.d/" > $@;

# read in the rules that list the dependencies for each object and dependency file
sinclude $(dependencies)

# compile each object file
$(objects) : obj/%.o : src/%.cpp
	$(CC) $(CC_FLAGS) $(GLOBAL_INC) -c $< -o $@;

# create the executable
bin/eds.exe : $(objects)
	$(CC) $(CC_FLAGS) $(objects) $(BLAS_LAPACK_LIB) -o $@;

# rule to clean up object and dependency files
.PHONY : clean
clean : 
	rm -f obj/*.o;
	rm -f obj/*.s;
	rm -f dep/*.d;

